package com.egao.orderB.controller2;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.orderB.entity.Province;
import com.egao.orderB.service.ProvinceService;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;


/**
 *
 * 省
 * @author : Doman
 * @date : 2020-10-20 11:20:43
 * @version ：1.0
 */

//@Api(tags = "省")
//@RestController
//@RequestMapping("/api/orderB/province")
public class ProvinceController extends BaseController {

	@Autowired
	private ProvinceService provinceService;

	/**
	 * 分页查询列表
	 */
    @OperLog(value = "省", desc = "分页查询")
    @ApiOperation("分页查询省")
    @ApiPageParam
    @PostMapping("/page")
    public JsonResult page(PageResult2<T> page, Province province) throws Exception{
        return provinceService.list(page, province, getLoginUser());
    }

    /**
     * 查询全部省
     */
    @OperLog(value = "省", desc = "查询全部")
    @ApiOperation("查询全部省")
    @PostMapping("/list")
    public JsonResult list(Province province){
        return provinceService.list(province, getLoginUser());
    }

    /**
     * 根据id查询省
     */
    @OperLog(value = "省", desc = "根据id查询")
    @ApiOperation("根据id查询省")
    @PostMapping("/get")
    public JsonResult get(Province province) {
        return provinceService.getById(province);
		// 使用关联查询
        //PageParam<province> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<province> records = provinceService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加省
     */
    @OperLog(value = "省", desc = "添加", param = false, result = true)
    @ApiOperation("添加省")
    @PostMapping("/save")
    public JsonResult save(Model model, Province province) {
        return provinceService.save(province, getLoginUser());
    }

    /**
     * 修改省
     */

    @OperLog(value = "省", desc = "修改", param = false, result = true)
    @ApiOperation("修改省")
    @PostMapping("/update")
    public JsonResult update(Model model, Province province) {
        return provinceService.update(province, getLoginUser());
    }

    /**
     * 删除省
     */
    @OperLog(value = "省", desc = "删除", result = true)
    @ApiOperation("删除省")
    @PostMapping("/remove")
    public JsonResult remove(Province province ) {
        return provinceService.remove(province, getLoginUser());
    }

    /**
     * 批量添加省
     */
    /**@RequiresPermissions("orderB:province:save")
    @OperLog(value = "省", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<Province> list) {
        if (provinceService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改省
     */
    /**@RequiresPermissions("orderB:province:update")
    @OperLog(value = "省", desc = "批量修改", result = true)
    @ResponseBody
    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<Province> batchParam) {
        if (batchParam.update(provinceService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除省
     */
    /**@RequiresPermissions("orderB:province:remove")
    @OperLog(value = "省", desc = "批量删除", result = true)
    @ResponseBody
    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (provinceService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
